import pygame
from pygame import time

pygame.init()

screen = pygame.display.set_mode((480,700))

timer = pygame.time.Clock()   # 创建时钟对象

background = pygame.image.load('./飞机大战/images/background.png')  # 背景图像
screen.blit(background,(0,0))

# 飞机精灵
class GameSprite(pygame.sprite.Sprite):

    def __init__(self, image, speed = 1):
        super().__init__()
        self.image = pygame.image.load(image)
        self.rect = self.image.get_rect()
        self.speed = speed

    def update(self):
        self.rect.y += self.speed

feiji = GameSprite('./飞机大战/images/enemy1.png') # 创建敌机
feiji2 = GameSprite('./飞机大战/images/enemy1.png',3)
feijiGroup = pygame.sprite.Group(feiji,feiji2)

# 游戏循环
while True:

    timer.tick(60)  # 1秒刷新60帧
    
    screen.blit(background,(0,0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print("游戏退出...")
            pygame.quit() # 卸载所有模块
            exit() # 终止当前执行的程序

    feijiGroup.update()
    feijiGroup.draw(screen)

    pygame.display.update()
